<?php
$host="db.seng.uvic.ca"; // Host name
$username="se321g01"; // Mysql username
$password="un8bi2YM"; // Mysql password
$db_name="se321g01"; // Database name
$tbl_name="user_info"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Personal
$firstname=$_POST['txtFirstName'];
$lastname=$_POST['txtLastName'];
$email=$_POST['txtEmail'];
$password=$_POST['Password'];

// Shipping
$scountry=$_POST['country'];
$sprovince=$_POST['province'];
$scity=$_POST['city'];
$saddress=$_POST['streetAddress'];
$spostal=$_POST['postalCode'];
$sphone=$_POST['phone'];

//Billing
$bcountry=$_POST['country2'];
$bprovince=$_POST['province2'];
$bcity=$_POST['city2'];
$baddress=$_POST['streetAddress2'];
$bpostal=$_POST['postalCode2'];
$bphone=$_POST['phone2'];
$bmethod=$_POST['credit'];
$bnumber=$_POST['cardnum'];
$bmonth=$_POST['cardmonth'];
$byear=$_POST['cardyear'];

// Insert into user_info
mysql_query("INSERT INTO user_info (first_name,last_name,email,passwd,admin) VALUES
('$firstname','$lastname','$email','$password',0)");

// Get UID
$sql="SELECT * FROM $tbl_name WHERE email='$email' and passwd='$password'";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
$uid = $row['uid'];

// Insert into shipping info
mysql_query("INSERT INTO shipping_info (country,province,city,street_address,postal_code,phone,uid) VALUES
('$scountry','$sprovince','$scity','$saddress', '$spostal', '$sphone','$uid')");

// Insert into billing info
mysql_query("INSERT INTO billing_info (country,province,city,street_address,postal_code,payment_method,card_number,expiry_date_year,expiry_date_month,uid) VALUES
('$bcountry','$bprovince','$bcity','$baddress', '$bpostal', '$bmethod','$bnumber','$byear','$bmonth','$uid')");

// Insert into user_stats
mysql_query("INSERT INTO user_stats (time_left, points, uid) VALUES
('0', '0', '$uid')");

// Go to profile
header("location:./user/profile.php?uid=" . $uid . "&tab=0");
?>
